<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>新增用户</title>
		<script type="text/javascript" src="scripts/jquery.min.js"></script>
		<script type="text/javascript" src="scripts/bootstrap.min.js"></script>
		<script type="text/javascript" src="scripts/jquery-1.10.2.min.js"></script>
		<script type="text/javascript" src="scripts/bootstrapValidator.js"></script>
		<link href="styles/bootstrap.min.css" rel="stylesheet" />
		<link href="styles/bootstrapValidator.css" rel="stylesheet" />
		<link rel="stylesheet" href="styles/select2.css">
		<script type="text/javascript" src="scripts/select2.js"></script>
</head>
<body>
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
		<h4 class="modal-title" id="myModalLabel">新增用户</h4>
	</div>
	<div class="modal-body">
		<form role="form" class="form-horizontal" method="post" id="userForm">
			<div class="form-group">
				<label class="col-sm-3 control-label">用户名：</label>
				<div class="col-sm-9">
					<input type="text" name="user.username" value="${user.username}" class="form-control" placeholder="请输入用户名" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">密码：</label>
				<div class="col-sm-9">
					<input type="password" name="user.password" value="${user.password}" class="form-control" placeholder="请输入密码" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">角色：</label>
				<div class="col-sm-9">
					<s:select list="roleList" name="user.roleId" value="user.roleId" listValue="role" listKey="id" cssClass="form-control">
					</s:select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">邮箱：</label>
				<div class="col-sm-9">
					<input type="text" name="user.email" class="form-control"  value="${user.email}" placeholder="请输入邮箱" />
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">电话：</label>
				<div class="col-sm-9">
					<input type="text" name="user.phone" class="form-control" value="${user.phone}" placeholder="请输入电话" />
				</div>
			</div>
		</form>
	</div>
	<div class="modal-footer">
		<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
		<button type="button" class="btn btn-primary" onclick="submit()">提交</button>
	</div>

	<script type="text/javascript">
		function submit() {
			if('${id}'>0){
				document.forms[0].action = "usersAction!update.action";
			}else{
				document.forms[0].action = "usersAction!create.action";
			}
			document.forms[0].submit();
		};
		$(function(){
			if('${id}'>0){
				$("#myModalLabel").text("修改用户");
			}
		});
	</script>
	
	<script type="text/javascript">
	$(document).ready(function() {
	    $('#userForm').bootstrapValidator({
	        message: 'This value is not valid',
	        feedbackIcons: {
	            valid: 'glyphicon glyphicon-ok',
	            invalid: 'glyphicon glyphicon-remove',
	            validating: 'glyphicon glyphicon-refresh'
	        },
	        fields: {
	            "user.username": {
	                message: 'The username is not valid',
	                validators: {
	                    notEmpty: {
	                        message: '用户名不能为空'
	                    }
	        		}
	            },
	            "user.password":{
	            	 message: 'The username is not valid',
		                validators: {
		                    notEmpty: {
		                        message: '密码不能为空'
		                    },
                			stringLength: {
                   				 min: 6,
                   				 max: 10,
                    			message: '密码必须在6-10位之间'
               				 }
		        	}
	            }
	        }
	        });
	});
	</script>
	

</body>
</html>